;
(function () {
    // 洞察工具类名
    TempoMineInsightUtils = {};
    TempoMineInsightUtils.PREPROCESS_OVERVIEWDESC = "overViewDesc";

    /**
     * 示例方法
     */
    TempoMineInsightUtils.methodA = function () {
        console.log("this is an example");
    }

    /**
     * 根据plugin_config.xml中配置的节点id和国际化文件中的.后面的字符串获取它的国际化值
     * 先从内存缓存中查询，如果存在就直接返回国际化值，如果不存在，则通过ajax请求获取，并保存到内存缓存中
     *
     * @param nodeConfigId
     *            plugin_config.xml中配置的节点id
     *          localeKey
     *              国际化文件中的.后面的字符串
     */
    TempoMineInsightUtils.getNodeLocalValue = function (nodeConfigId, localeKey) {
        var key = nodeConfigId + '.' + localeKey;
        var value = null;
        if (nodeConfigId) {
            $.ajax({
                url: contextPath + "/api/ai/mine/loadI18nByType",
                data: {
                    type: nodeConfigId
                },
                type: 'post',
                async: false,
                success: function (result) {
                    value = result[localeKey];
                },
                error: function () {
                    value = null;
                }
            });
        }
        return value;
    }

    /**
     * 根据洞察信息得到预处理节点的描述信息
     *
     * @param insightInfo
     *             表pf_tempo_mine_insight中记录字段info的值,即节点洞察信息
     */
    TempoMineInsightUtils.getPreprocessNodeDesc = function (insightInfo) {
        var overViewDesc = insightInfo.overViewDesc;
        var nodeConfigId = insightInfo.nodeConfigId;
        var nodeDesc = TempoMineInsightUtils.getNodeLocalValue(nodeConfigId, TempoMineInsightUtils.PREPROCESS_OVERVIEWDESC);
        if (insightInfo.histroy == false) {
            nodeDesc = TempoMineInsightUtils.getNodeLocalValue(nodeConfigId, TempoMineInsightUtils.PREPROCESS_OVERVIEWDESC + "New");
            nodeDesc = nodeDesc.replace("tablesNameString", insightInfo.tablesNameString)
        }
        if(overViewDesc) {
            var keys = Object.keys(overViewDesc);
            if (keys.length > 0) {
                for (var i = 0; i < keys.length; i++) {
                    if ($.trim(overViewDesc[keys[i]]).length == 0) {
                        nodeDesc = nodeDesc.replace(keys[i], TempoUtils.locale("mine.black"));
                    } else {
                        nodeDesc = nodeDesc.replace(eval("/" + keys[i] + "/g"), overViewDesc[keys[i]]);
                    }
                }
            }
        }
        var childLocaleKeyList = insightInfo.childLocaleKeyList;
        if (childLocaleKeyList && childLocaleKeyList.length > 0) {
            for (var i = 0; i < childLocaleKeyList.length; i++) {
                var childLocaleKey = childLocaleKeyList[i];
                // 若传入的childLocaleKey中有.  ，则直接加载国际化文件【即一些公共的国际化文件】
                if (childLocaleKey.indexOf(".") > -1 && TempoUtils.locale(childLocaleKey)) {
                    nodeDesc = nodeDesc.replace(eval("/" + childLocaleKey + "/g"), TempoUtils.locale(childLocaleKey));
                    continue;
                }
                var childLocaleVal = TempoMineInsightUtils.getNodeLocalValue(nodeConfigId, childLocaleKey);
                var key = nodeConfigId + '.' + childLocaleKey;
                nodeDesc = nodeDesc.replace(eval("/" + key + "/g"), childLocaleVal);
            }
        }
        return nodeDesc;
    }

    /**
     * 根据洞察信息，节点名称创建 过程洞察->处理节点的描述表格
     * @param insightInfo
     *            表pf_tempo_mine_insight中记录字段info的值,即节点洞察信息
     *          nodeName
     *            节点名称
     *          parentElement
     *            表格的父容器
     */
//	TempoMineInsightUtils.createPreprocessNodeDescTable = function(insightInfo, nodeName, parentElement) {
//		var descDiv=$('<div/>',{
//			"class":"tempo-mine-preprocessnode-insight-nodedesc"
//		}).appendTo(parentElement);
//		var nodeDesc = TempoMineInsightUtils.getPreprocessNodeDesc(insightInfo);
//		var descTable=$('<table/>',{
//			width:descDiv.width(),
//			"class":"tempo-mine-insight-table-with-worddesc"
//		}).append($('<thead><tr><th>'+TempoUtils.locale('mine.nodename')+'</th><th>' + TempoUtils.locale('mine.nodedesc') + '</th></tr></thead>')).appendTo(descDiv);
//		$('<tr><td>'+ nodeName + '</td><td>'+nodeDesc+'</td></tr>').appendTo(descTable);
//	}

    /**
     * 根据洞察信息，节点名称创建 过程洞察->处理节点的描述
     * @param insightInfo
     *            表pf_tempo_mine_insight中记录字段info的值,即节点洞察信息
     *          nodeName
     *            节点名称
     *          parentElement
     *            表格的父容器
     */
    TempoMineInsightUtils.createPreprocessNodeDescTable = function (insightInfo, nodeName, parentElement) {

        var descDiv = $('<div/>', {
            "class": "tempo-mine-preprocessnode-insight-nodedesc"

        }).appendTo(parentElement);
        var nodeDesc = TempoMineInsightUtils.getPreprocessNodeDesc(insightInfo);
        if (nodeDesc == null || typeof (nodeDesc) == "undefined") {
            nodeDesc = "";
        }


        var p = $("<p class='binning-insig-p' style='word-break:break-all;white-space:normal;'></p>");
        if (insightInfo.nodeConfigId == "binning") {
            descDiv.append($('<span>').addClass('nodedesc-nodename').text(nodeName))
                .append(p.addClass('nodedesc-content').append("<span class='ui-icon tempo-ui-icon tempo-ui-icon-tip tempo-mine-preprocess-desc-pre-icon' style='margin-top: -3px'></span>" + nodeDesc));
            var insightP = $(".binning-insig-p");
            insightP.css("margin-top", "10px");
            insightP.css("background-color", "#f1f8ed");
            insightP.css("border", "1px solid #d6e9c6");
            insightP.css("color", "#599925");
            insightP.css("font-weight", "bold");
        } else {
            descDiv.append($('<span>').addClass('nodedesc-nodename').text(nodeName))
                .append($('<p style="word-break:break-all;white-space:normal;"/>').addClass('nodedesc-content').text(nodeDesc));

        }
    }

    /**
     * 根据洞察信息，添加数据预处理的条件展示的Div
     * @param insightInfo：表pf_tempo_mine_insight中记录字段info的值,即节点洞察信息
     *          nodeName ：节点名称
     *          parentElement：表格的父容器
     *          className ：div的class内容，可自己设置不同的样式，若不需要特殊设置，可不传该参数
     */
    TempoMineInsightUtils.createPreprocessNodeProfileDiv = function (insightInfo, nodeName, parentElement, className) {
        var profileText = nodeName + "-" + TempoUtils.locale("mine.node_insight_conditional");
        if (insightInfo.nodeConfigId != "transpose" && insightInfo.profile) {
            profileText += " " + insightInfo.profile;
            // 处理条件中的国际化标签
            var localeList = insightInfo.profileLocaleKeyList;
            if (localeList && localeList.length > 0) {
                for (var i = 0; i < localeList.length; i++) {
                    profileText = profileText.replace(eval("/" + localeList[i] + "/g"), TempoUtils.locale(localeList[i]));
                }
            }
        }
        if (!className) {
            // 若className为空，则置为空串
            className = "";
        }
        if (insightInfo.nodeConfigId == "binning") {
            $("<label class='.binning-text'>" + "； " + profileText + "</lable>").appendTo($(".binning-insig-p"));
        } else {
            $('<div class="deal-desc' + className + '" style="margin-top:0px"><p><i class="ui-icon tempo-ui-icon tempo-ui-icon-tip tempo-mine-preprocess-desc-pre-icon"></i><label>' + TempoUtils.htmlEscape(profileText) + '</label></p></div>').appendTo(parentElement);
        }
    }

    /**
     * 根据洞察信息，添加数据预处理条件Div
     * @param titleTable：表格对象信息，即PreprocessInsightData中的TitleTable对象
     *          parentElement：表格的父容器
     *          className ：表格所属div的class内容，可自己设置不同的样式，若不需要特殊设置，可不传该参数
     */
    TempoMineInsightUtils.createPreprocessTitleTable = function (titleTable, parentElement, className) {
        if (!titleTable) {
            console.error("Param titleTable is undefined or null!");
            return;
        }
        var describ = "";
        var thisParentDiv = $("<div class='" + className + "'/>").appendTo(parentElement);
        if (titleTable.describ) {
            describ += titleTable.describ;
            $('<div style="height:15px;font-weight:bold;padding-right:10px;padding-top:10px">' + describ + '</div>').appendTo(thisParentDiv);
        }
        if (titleTable.nameString) {
            $('<div style="height:15px;font-weight:bold;padding-right:10px;padding-top:10px">' + titleTable.nameString + '</div>').appendTo(thisParentDiv);
        }
        if (!className) {
            className = "";
        }
        var titleDiv = $("<div style='padding-top:10px;overflow:auto'/>").appendTo(thisParentDiv);
        //添加节点洞察数据集为空显示提示
        if (titleTable.body && titleTable.body.length <= 1) {
            TempoMineInsightUtils.showNullDatasetInsight(titleDiv);
        }
        var tableElement = TempoMineUtils.buildTableByMeta(titleTable.body, titleTable.head, "tempo-mine-insight-table", titleTable.title, titleTable.flag);
        tableElement.appendTo(titleDiv);
    }


    /** 高度距离问题
     * 根据洞察信息，添加数据预处理条件Div
     * @param titleTable：表格对象信息，即PreprocessInsightData中的TitleTable对象
     *          parentElement：表格的父容器
     *          className ：表格所属div的class内容，可自己设置不同的样式，若不需要特殊设置，可不传该参数
     */
    TempoMineInsightUtils.createPreprocessTitleTableOne = function (titleTable, parentElement, className) {
        if (!titleTable) {
            console.error("Param titleTable is undefined or null!");
            return;
        }
        var describ = "";
        if (titleTable.describ) {
            describ += titleTable.describ;
        }
        var thisParentDiv = $("<div class='" + className + "'/>").appendTo(parentElement);
        $('<div style="height:0px;font-weight:bold;padding-right:10px;padding-top:0px">' + describ + '</div>').appendTo(thisParentDiv);
        if (!className) {
            className = "";
        }
        var titleDiv = $("<div style='padding-top:15px;overflow:auto'/>").appendTo(thisParentDiv);
        var tableElement = TempoMineUtils.buildTableByMeta(titleTable.body, titleTable.head, "tempo-mine-insight-table", titleTable.title);
        if (titleTable.body.length == 0) {
            TempoMineInsightUtils.showNullDatasetInsight(titleDiv);
        }
        tableElement.appendTo(titleDiv);
    }
    /**
     * 数据连接节点修改洞察样式后的展现函数
     */
    TempoMineInsightUtils.addPreprocessElementJoin = function (data, nodeName, parentElement) {
        //数据连接 descDiv
        var descDiv = $('<div/>', {
            "class": "tempo-mine-preprocessnode-insight-nodedesc"
        }).appendTo(parentElement);
        descDiv.append($('<span>').addClass('nodedesc-nodename').text(nodeName));
        //数据连接设置条件 conditionDiv
        var profileText = nodeName + "-" + TempoUtils.locale("mine.node_insight_conditional");
        // 处理条件中的国际化标签
        var localeList = data.profileLocaleKeyList;
        var conditionDiv = $('<div class="deal-desc"><p class="tempo-join"><i class="ui-icon tempo-ui-icon tempo-ui-icon-tip tempo-mine-preprocess-desc-pre-icon"></i><span>' + profileText + '</span></p></div>');
        data.profile.split("|").forEach(function (v) {
            if (localeList && localeList.length > 0) {
                for (var i = 0; i < localeList.length; i++) {
                    v = v.replace(eval("/" + localeList[i] + "/g"), TempoUtils.locale(localeList[i]));
                }
            }
            conditionDiv.find(".tempo-join").append($("<br/><span style='margin-left:108px' >" + v + "</span>"));
        })
        conditionDiv.appendTo(parentElement);

        if (!data.titleTables) {
            return;
        }
        // 若表格个数小于等于2，则每行只显示一个表格，若大于2，则每行显示两个表格
        var tableDivClass = "";
        // 现改为每个表占一行,所以将此注释，好改回去
        // if (data.titleTables.length > 2){
        // 	tableDivClass = "temp-mine-insight-processtable-div";
        // }
        for (var i = 0; i < data.titleTables.length; i++) {
            var titleTable = data.titleTables[i];
            TempoMineInsightUtils.createPreprocessTitleTable(titleTable, parentElement, tableDivClass);
        }
        // 现改为每个表占一行,所以将此注释，好改回去
        // 每行只显示两个，设置表格所在div样式，使一行显示两个表格
        // var divWidth = "47%";
        // var doubleDivWidth = "98%";
        // var peWidth = parentElement.width();
        // if (peWidth > 0){
        // 	// 处理1366*768分辨率下，两张表同行显示
        // 	if(peWidth > 890 && peWidth < 940){
        // 		peWidth = 885;
        // 	}
        // 	// 处理1600*900分辨率下，两张表同行显示
        // 	if(peWidth > 1120 && peWidth < 1170){
        // 		peWidth = 1110;
        // 	}
        // 	if(peWidth > 1450 && peWidth < 1500){
        // 		peWidth = 1443;
        // 	}
        // 	if(peWidth > 1600 && peWidth < 1650){
        // 		peWidth = 1593;
        // 	}
        // 	divWidth = (peWidth-64)/2;
        // 	doubleDivWidth = peWidth-64;
        // }
        // var divStyle = {
        // 	"width":divWidth,
        // 	"float":'left',
        // 	"padding-right":"20px"
        // }
        // if (tableDivClass != ""){
        // 	parentElement.find("."+tableDivClass).css(divStyle);
        // }
        // 若表格个数超过两个，且为奇数个，则最后一个表格将占满所在行
        // var tableLength = data.titleTables.length;
        // $(parentElement.find("."+tableDivClass)[tableLength-1]).css({"width":doubleDivWidth});
    }

    /**
     * 预处理节点：添加节点描述及处理过程中的数据内容显示到父容器上
     * @param insightInfo：洞察数据对象
     *          nodeName：节点名称
     *          parentElement ：父容器
     */
    TempoMineInsightUtils.addPreprocessElement = function (insightInfo, nodeName, parentElement) {
        // 添加节点描述
        if (insightInfo.nodeConfigId == "balance" || insightInfo.nodeConfigId == "renameattributes" || insightInfo.nodeConfigId == "rfm" || insightInfo.nodeConfigId == "anomalydetection" || insightInfo.nodeConfigId == "transpose" || insightInfo.nodeConfigId == "localpolyregfitting" || insightInfo.nodeConfigId == "numerictransform" || insightInfo.nodeConfigId == "datetimetransform" || insightInfo.nodeConfigId == "chartransform" || insightInfo.nodeConfigId == "outlierdetection") {
            TempoMineInsightUtils.createPreprocessNodeDescTable("", nodeName, parentElement);
        } else {
            TempoMineInsightUtils.createPreprocessNodeDescTable(insightInfo, nodeName, parentElement);
        }

        // 添加属性变换条件
        TempoMineInsightUtils.createPreprocessNodeProfileDiv(insightInfo, nodeName, parentElement);
        if (!insightInfo.titleTables) {
            return;
        }
        // 若表格个数小于等于2，则每行只显示一个表格，若大于2，则每行显示两个表格
        var tableDivClass = "";
        if (insightInfo.titleTables.length > 2) {
            tableDivClass = "temp-mine-insight-processtable-div";
        }
        for (var i = 0; i < insightInfo.titleTables.length; i++) {
            var titleTable = insightInfo.titleTables[i];
            TempoMineInsightUtils.createPreprocessTitleTable(titleTable, parentElement, tableDivClass);
        }
        // 每行只显示两个，设置表格所在div样式，使一行显示两个表格
        var divWidth = "47%";
        var doubleDivWidth = "98%";
        if (parentElement.width() > 0) {
            divWidth = (parentElement.width() - 64) / 2;
            doubleDivWidth = parentElement.width() - 64;
        }
        var divStyle = {
            "width": divWidth,
            "float": 'left',
            "padding-right": "20px"
        }
        if (tableDivClass != "") {
            parentElement.find("." + tableDivClass).css(divStyle);
        }
        // 若表格个数超过两个，且为奇数个，则最后一个表格将占满所在行
        var tableLength = insightInfo.titleTables.length;
        if (tableLength > 2 && tableLength % 2 == 1) {
            $(parentElement.find("." + tableDivClass)[tableLength - 1]).css({"width": doubleDivWidth});
        }
    }

    /**
     * 构建文件挖掘洞察中的列表
     * insightData 洞察数据
     * container 列表容器
     * @param meta 表头信息，用来替换列表显示头
     * showMore 显示全部数据
     */
    TempoMineInsightUtils.createWordMingingDatasetTable = function (insightData, container, meta, showMore) {
        // 结果集第一行为类型，第二行为列名，第三行开始为数据
        var datasetData1 = insightData.resultDataset;
        var datasetData = [];
        if (datasetData1 && datasetData1.length > 0 && showMore != undefined && showMore == false) {
            var lineData = datasetData1[0];
            // 如果输出数据列超过17列，则只显示前后8列数据，中间用...显示
            if (lineData && lineData.length > 17) {
                for (var i = 0; i < datasetData1.length; i++) {
                    var rowData = datasetData1[i];
                    var newRowData = rowData.slice(0, 8);
                    newRowData.push("...");
                    newRowData = newRowData.concat(rowData.slice(-8));
                    datasetData.push(newRowData);
                }
            } else {
                datasetData = datasetData1;
            }
        } else {
            datasetData = datasetData1;
        }
        var roleData = datasetData[1];
        var roleIndex = "";
        // 特征选择列名称转换
        var transfer = function (name) {
            if (meta && meta[name] && meta[name].name) {
                return meta[name].name;
            } else {
                return name;
            }
        }
        // 列名为第二行元素
        var columnNames = datasetData[1];
        if (columnNames && columnNames.length > 0) {
            for (var i = 0; i < columnNames.length; i++) {
                columnNames[i] = transfer(columnNames[i]);
            }
        }
        if (datasetData && datasetData.length > 2) {
            // 删除列名
            datasetData.splice(1, 1);
            var dataParser = function (value) {
                //解析向量值
                if (value && typeof value == 'object') {
                    try {
                        for (var i in value) {
                            if (typeof value[i] == 'number') {
                                value[i] = TempoMineUtils.format(value[i])
                            }
                        }
                        if (roleData[roleIndex] == "wordSeg") {
                            console.log("wordSeg===>");
                            //分詞列處理
                            if (JSON.stringify(value).length > 197) {
                                var newString = JSON.stringify(value).substring(0, 197) + "...";
                                return newString;
                            } else {
                                return JSON.stringify(value);
                            }
                        }

                    } catch (e) {
                    }
                }
                //尝试格式化
                return TempoMineUtils.format(value, false);
            }
            for (var m = 1; m < datasetData.length; m++) {
                var datarow = datasetData[m];
                if (datarow && datarow.length > 0) {
                    for (var i = 0; i < datarow.length; i++) {
                        roleIndex = i;
                        datarow[i] = dataParser(datarow[i]);
                    }
                }
            }
            var tableElement = TempoMineUtils.buildTableByMeta(datasetData, columnNames, "tempo-mine-textming-insight-table", "");
            tableElement.appendTo(container);
        } else {
            var tableElement = TempoMineUtils.buildTableByMeta([], columnNames, "tempo-mine-textming-insight-table", "");
            //数据集为空
            TempoMineInsightUtils.showNullDatasetInsight(container);
            tableElement.appendTo(container);

        }
    }

    /**
     * 新增加的列，全是空数据的列放在最后面
     * resultDataset；结果集，第一行为类型，第二行为列名，第三行开始为数据
     * addMetadatas：新增的列的元信息
     */
    TempoMineInsightUtils.resetDataOrder = function (resultDataset, addMetadatas) {
        if (!addMetadatas || addMetadatas.length == 0) {
            return resultDataset;
        }
        var metaCache = {};
        // resultDataset第二行为列名
        var allColumns = resultDataset[1];
        // 缓存新增列的下标
        var addColumnIndex = [];
        for (var i = 0; i < addMetadatas.length; i++) {
            var metaItem = TempoMineMetaUtils.convertMetaToObj(addMetadatas[i]);
            if (allColumns.indexOf(metaItem.desc) != -1) {
                addColumnIndex.push(allColumns.indexOf(metaItem.desc));
            }
        }
        // 下标按从小到大进行排列
        addColumnIndex.sort(function (a, b) {
            return a - b;
        });
        // 缓存数据全为空的列的下标，默认所有新增的列数据都是空的
        var allColumnDataEmptyIndex = TempoUtils.clone(addColumnIndex);
        for (var i = 2; i < resultDataset.length; i++) {
            if (allColumnDataEmptyIndex.length == 0) {
                break;
            }
            // 若最后一行全是...，则跳过
            if (i == resultDataset.length - 1) {
                var flag = true;
                for (var j = 0; j < resultDataset[i]; j++) {
                    if (resultDataset[i][j] != "...") {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    break;
                }
            }
            for (var j = allColumnDataEmptyIndex.length - 1; j >= 0; j--) {
                // 数据不为空，将该下标从allColumnDataEmptyIndex中删掉
                if (resultDataset[i][allColumnDataEmptyIndex[j]] && resultDataset[i][allColumnDataEmptyIndex[j]] != "") {
                    allColumnDataEmptyIndex.splice(j, 1);
                }
            }
        }
        // 若没有不是空数据的，则直接返回数据
        if (allColumnDataEmptyIndex.length == 0) {
            return resultDataset;
        }
        var res = TempoUtils.clone(resultDataset);
        allColumnDataEmptyIndex.sort(function (a, b) {
            return a - b;
        });
        // 调整空列所对应下标的数据
        for (var i = 0; i < res.length; i++) {
            var row = res[i];
            var emptyRow = [];
            for (var j = allColumnDataEmptyIndex.length - 1; j >= 0; j--) {
                emptyRow.push(row[allColumnDataEmptyIndex[j]]);
                row.splice(allColumnDataEmptyIndex[j], 1);
            }
            res[i] = res[i].concat(emptyRow);
        }
        return res;
    }

    TempoMineInsightUtils.showSignWriteFileDataView = function (viewData, parentDiv) {
        var columnNum = viewData.columnNum;
        var rowNum = viewData.rowNum;
        var viewContent = viewData.viewContent;
        var contentDiv = $("<div style='width:100%;height:90%;overflow:auto'>").appendTo(parentDiv);
        $('<span style="display: block;margin-left:10px;margin-bottom:10px;"></span>').text("输出数据统计：共" + rowNum + "行，" + columnNum + "列").appendTo(contentDiv);
        var viewContentJson = viewContent.split(";");
        var tBody = [];
        var tHead = [];
        if (viewContentJson && viewContentJson.length && viewContentJson.length > 0) {
            for (var i = 0; i < viewContentJson.length; i++) {
                var contentItem = viewContentJson[i];
                var contentItemArr = contentItem.split("$&^");
                if (i == 0) {
                    tBody.push(contentItemArr);
                    tHead = contentItemArr;
                } else {
                    var dataStr = "[";
                    var array = contentItemArr[3].substring(1, contentItemArr[3].length - 1).split(",")
                    for (var j = 0; j < array.length; j++) {
                        var endsWithFlag = array[j].endsWith(".0");
                        var value = array[j];
                        if (endsWithFlag) {
                            value = parseInt(value)
                        }
                        dataStr = dataStr + value + ",";
                    }
                    contentItemArr[3] = dataStr + "]";
                    tBody.push(contentItemArr);
                }
            }
            var tableElement = TempoMineUtils.buildTableByMeta(tBody, tHead, "tempo-mine-insight-table", "", window.mineConstant.PORT_SIGNAL);
            var tableParentDiv = $("<div id='tempo-mine-viewing-resultshow' style='width:100%;'>").appendTo(contentDiv);
            $(tableElement).appendTo(tableParentDiv);
        }
    }

    TempoMineInsightUtils.showWriteFileDataView = function (viewData, parentDiv) {
        var columnNum = viewData.columnNum;
        var rowNum = viewData.rowNum;
        var viewContent = viewData.viewContent;
        var contentDiv = $("<div style='width:100%;height:90%;overflow:auto'>").appendTo(parentDiv);
        $('<span style="display: block;margin-left:10px;margin-bottom:10px;"></span>').text("输出数据统计：共" + rowNum + "行，" + columnNum + "列").appendTo(contentDiv);
        var viewContentJson = JSON.parse(viewContent);
        var tBody = [];
        var tHead = [];

        if (viewContentJson && viewContentJson.length && viewContentJson.length > 0) {
            for (var i = 0; i < viewContentJson.length; i++) {
                var contentItem = viewContentJson[i];
                var contentItemArr = contentItem.split("$&^");
                if (i == 0) {
                    tBody.push(contentItemArr);
                    tHead = contentItemArr;
                } else {
                    //double和float获取的时候已经是科学计数法的样子了，需要还原
                    for (var x = 0; x < contentItemArr.length; x++) {
                        if (contentItemArr[x].split("E").length > 2) {
                            continue;
                        }
                        if (contentItemArr[x].split("E").length == 2 && (Number(contentItemArr[x].split("E")[0]).toString() == "NaN" || Number(contentItemArr[x].split("E")[1]).toString() == "NaN")) {
                            continue;
                        }
                        if (contentItemArr[x].indexOf(".") > -1 && contentItemArr[x].indexOf("E") > -1) {
                            contentItemArr[x] = Number(contentItemArr[x]);
                        }
                    }
                    tBody.push(contentItemArr);
                }
            }
            var tableElement = TempoMineUtils.buildTableByMeta(tBody, tHead, "tempo-mine-insight-table", null);
            var tableParentDiv = $("<div id='tempo-mine-viewing-resultshow' style='width:100%;'>").appendTo(contentDiv);
            $(tableElement).appendTo(tableParentDiv);
        }
    }

    TempoMineInsightUtils.showWriteFileDataViews = function (viewData, parentDiv, fileType) {

        var columnNumList = viewData.columnNum.split("^&$");
        var rowNumList = viewData.rowNum.split("^&$");
        var viewContentList = viewData.viewContent.split("^&$");
        var num = columnNumList.length;
        var contentDiv = $("<div style='width:100%;height:100%;overflow:auto'>").appendTo(parentDiv);
        var selectDiv = $("<div style='width:100%;height:10%;overflow:auto;border-bottom: 1px solid #c0c9d5;'>").appendTo(contentDiv);
        //var showDataDiv = $("<div style='width:100%;height:85%;overflow:auto'>").appendTo(contentDiv);
        for (var j = 1; j <= num; j++) {
            //标签
            $("<div class='showTab_" + j + "' style='display: inline-block;height: 33px;width: 60px;text-align: center;line-height: 2.5;cursor: pointer;'>sheet" + j + "</div>").appendTo(selectDiv);
            //展示数据区域
            var showDataDiv = $("<div class='showDataDiv_" + j + "' style='width:100%;height:85%;overflow:auto;border-bottom: 1px solid #c0c9d5;'>").appendTo(contentDiv);
            $('<span style="display: block;margin-left:10px;margin-bottom:10px;margin-top: 10px;"></span>').text("输出数据统计：共" + rowNumList[j - 1] + "行，" + columnNumList[j - 1] + "列").appendTo(showDataDiv);
            var viewContentJson = JSON.parse(viewContentList[j - 1]);
            var tBody = [];
            var tHead = [];

            if (viewContentJson && viewContentJson.length && viewContentJson.length > 0) {
                for (var i = 0; i < viewContentJson.length; i++) {
                    var contentItem = viewContentJson[i];
                    var contentItemArr = contentItem.split("$&^");
                    if (i == 0) {
                        tBody.push(contentItemArr);
                        tHead = contentItemArr;
                    } else {
                        //double和float获取的时候已经是科学计数法的样子了，需要还原
                        for (var x = 0; x < contentItemArr.length; x++) {
                            if (contentItemArr[x].split("E").length > 2) {
                                continue;
                            }
                            if (contentItemArr[x].split("E").length == 2 && (Number(contentItemArr[x].split("E")[0]).toString() == "NaN" || Number(contentItemArr[x].split("E")[1]).toString() == "NaN")) {
                                continue;
                            }
                            if (contentItemArr[x].indexOf(".") > -1 && contentItemArr[x].indexOf("E") > -1) {
                                contentItemArr[x] = Number(contentItemArr[x]);
                            }
                        }
                        tBody.push(contentItemArr);
                    }
                }
                var tableElement = TempoMineUtils.buildTableByMeta(tBody, tHead, "tempo-mine-insight-table", null);
                var tableParentDiv = $("<div id='tempo-mine-viewing-resultshow' style='width:100%;'>").appendTo(showDataDiv);
                $(tableElement).appendTo(tableParentDiv);
            }
            if (j == 1) {
                contentDiv.find("div[class='showTab_" + j + "']").css("border-bottom", "1px solid #289de9").css("color", "#289de9")
            } else {
                showDataDiv.hide();
            }
        }
        //给标签增加点击事件
        contentDiv.find("div[class^='showTab_']").click(function (e) {
            //sheet页序号
            var number = $(this).attr("class").split("_")[1];
            $("div[class^='showTab_']").css("border-bottom", "").css("color", "");
            $(".showTab_" + number).css("border-bottom", "1px solid #289de9").css("color", "#289de9");
            $("div[class^='showDataDiv_']").hide();
            $(".showDataDiv_" + number).show();
        });
    }

    /**
     * 文件输出列表查看前10行数据
     * @param fileInfo 文件输出
     * @param dataDialog 数据预览弹框
     */
    TempoMineInsightUtils.writeFileDataView = function (fileInfo, dataDialog) {
        //文件类型
        var fileType = fileInfo.fileType;
        //是否输出同一excel
        var isSameExcel = fileInfo.isSameExcel;
        if (fileType == "xlsx" && isSameExcel == "true") {
            //输出同一excel
            //数据列数
            var columnNumList = JSON.parse(fileInfo.columnNum);
            //数据行数
            var rowNumList = JSON.parse(fileInfo.rowNum);
            //数据
            var viewContentList = JSON.parse(fileInfo.viewContent);
            //sheet页签名称
            var sheetNames = JSON.parse(fileInfo.sheetNames);
            var contentDiv = $("<div style='width:100%;height:100%;overflow:auto'>").appendTo(dataDialog);
            var selectDiv = $("<div style='width:100%;height:10%;overflow:hidden;border-bottom: 1px solid #c0c9d5;'>").appendTo(contentDiv);
            for (var i = 0; i < sheetNames.length; i++) {
                //标签
                var showTabSpan = $("<span class='showTab_" + i + "' " +
                    "style='display: inline-block;width: 50px;text-align: center;cursor: pointer;text-overflow: ellipsis;overflow: hidden;white-space: nowrap;padding: 8px;cursor: pointer;'>"
                    + sheetNames[i] + "</span>").appendTo(selectDiv);
                //将sheet页签名称保存到data中
                showTabSpan.data("sheetName", i).attr("title", sheetNames[i]);
                //展示数据区域
                var showDataDiv = $("<div class='showDataDiv_" + i + "' style='width:100%;height:85%;overflow:auto;'>").appendTo(contentDiv);
                $('<span style="display: block;margin-left:10px;margin-bottom:10px;margin-top: 10px;"></span>').text("输出数据统计：共" + rowNumList[i] + "行，" + columnNumList[i] + "列").appendTo(showDataDiv);
                var viewContent = viewContentList[i];
                var tBody = [];
                var tHead = [];
                if (viewContent && viewContent.length > 0) {
                    for (var j = 0; j < viewContent.length; j++) {
                        //获取本行数据
                        var contentItem = TempoUtils.clone(viewContent[j]);
                        //获取数据类型
                        var contentItemType = viewContent[1];
                        if (j == 0) {
                            tBody.push(contentItem);
                            tHead = contentItem;
                        } else {
                            //类型行不进行展示
                            if (j != 1) {
                                for (var k = 0; k < contentItem.length; k++) {
                                    var value = contentItem[k];
                                    if ($.isNumeric(value) && contentItemType[k] != TempoMineMetaUtils.DATATYPES.STRING) {
                                        contentItem[k] = TempoMineUtils.format(value, false);
                                    }
                                }
                                tBody.push(contentItem);
                            }
                        }
                    }
                    var tableElement = TempoMineUtils.buildTableByMeta(tBody, tHead, "tempo-mine-insight-table", null);
                    var tableParentDiv = $("<div id='tempo-mine-viewing-resultshow' style='width:100%;'>").appendTo(showDataDiv);
                    $(tableElement).appendTo(tableParentDiv);
                }
                //默认选中第一个sheet页签
                if (i == 0) {
                    contentDiv.find("span[class='showTab_" + i + "']").css("border-bottom", "1px solid #289de9").css("color", "#289de9")
                } else {
                    showDataDiv.hide();
                }
            }
            //给标签增加点击事件
            contentDiv.find("span[class^='showTab_']").click(function (e) {
                //sheet页序号
                var showTabClass = $(this).attr("class");
                //获取对应页签的名称
                var sheetName = $(this).data("sheetName");
                //去掉其它页签的选中状态
                contentDiv.find("span[class^='showTab_']").css("border-bottom", "").css("color", "");
                contentDiv.find("." + showTabClass).css("border-bottom", "1px solid #289de9").css("color", "#289de9");
                //隐藏全部
                contentDiv.find("div[class^='showDataDiv_']").hide();
                //显示选中的数据
                contentDiv.find(".showDataDiv_" + sheetName).show();
            });
        } else {
            //处理输出同一excel的其它情况
            //数据列数
            var columnNum = fileInfo.columnNum;
            //数据行数
            var rowNum = fileInfo.rowNum;
            //数据
            var viewContent = JSON.parse(fileInfo.viewContent);
            var contentDiv = $("<div style='width:100%;height:90%;overflow:auto'>").appendTo(dataDialog);
            $('<span style="display: block;margin-left:10px;margin-bottom:10px;"></span>').text("输出数据统计：共" + rowNum + "行，" + columnNum + "列").appendTo(contentDiv);
            var tBody = [];
            var tHead = [];
            if (viewContent && viewContent.length > 0) {
                for (var i = 0; i < viewContent.length; i++) {
                    var contentItem = viewContent[i];
                    //获取数据类型
                    var contentItemType = viewContent[1];
                    if (i == 0) {
                        tBody.push(contentItem);
                        tHead = contentItem;
                    } else {
                        //类型行不进行展示
                        if (i != 1) {
                            for (var k = 0; k < contentItem.length; k++) {
                                var value = contentItem[k];
                                if ($.isNumeric(value) && contentItemType[k] != TempoMineMetaUtils.DATATYPES.STRING) {
                                    contentItem[k] = TempoMineUtils.format(value, false);
                                }
                            }
                            tBody.push(contentItem);
                        }
                    }
                }
                var tableElement = TempoMineUtils.buildTableByMeta(tBody, tHead, "tempo-mine-insight-table", null);
                var tableParentDiv = $("<div id='tempo-mine-viewing-resultshow' style='width:100%;'>").appendTo(contentDiv);
                $(tableElement).appendTo(tableParentDiv);
            }
        }
    }

    TempoMineInsightUtils.showPMMLModelInsight = function (insightInfo, configParentDiv) {

        var nodeIdToNameMap = {
            logisticregression: 'Logistic Regression',
            xgboost: 'Xgboost Classification',
            kmeans: 'KMeans',
            linearregression: 'Linear Regression',
            decisiontreereg: 'Decision Tree Regression',
            randomforestreg: 'Random Forest Regression',
            gbtregression: 'GBDT Regression',
            neuralnetwork: 'BP Neural Net Classification',
            decisiontree: 'CART',
            randomforest: 'Random Forest Classification',
            id3: 'ID3 Classification'
        };
        var modelName = insightInfo.modelName;
        var copyRight = insightInfo.copyRight;
        var pmmlVersion = insightInfo.pmmlVersion;
        var modelVersion = insightInfo.modelVersion;
        var modelType = insightInfo.modelType;
        var dataDictionary = insightInfo.dataDictionary;
        var miningSchema = insightInfo.miningSchema;
        var timestamp = insightInfo.timestamp;
        var dataDictionaryStr = "";
        for (var i = 0; i < dataDictionary.length; i++) {
            var dataDic = dataDictionary[i];
            if (i != dataDictionary.length - 1) {
                dataDictionaryStr += dataDic["field"] + "（" + dataDic["type"].toUpperCase() + "），";
            } else {
                dataDictionaryStr += dataDic["field"] + "（" + dataDic["type"].toUpperCase() + "）";
            }
        }
        var predictFiledStr = "";
        var labelStr = "";
        var predictLen = 0;
        var labelLen = 0;
        for (var i = 0; i < miningSchema.length; i++) {
            var schemaItem = miningSchema[i];
            if (schemaItem["type"] == "label") {
                labelStr += schemaItem["field"] + "，";
                labelLen++;
            } else {
                predictFiledStr += schemaItem["field"] + "，";
                predictLen++;
            }
        }
        if (labelLen == 0) {
            labelStr += TempoUtils.locale("mine.none");
        } else {
            labelStr = labelStr.substring(0, labelStr.length - 1);
        }
        if (predictLen == 0) {
            predictFiledStr += TempoUtils.locale("mine.none");
        } else {
            predictFiledStr = predictFiledStr.substring(0, predictFiledStr.length - 1);
        }
        var idx = modelVersion.lastIndexOf("_");
        var pmmlInsightDiv = $($(".tempo-pmml-insight")[0]).clone().appendTo(configParentDiv).show();
        pmmlInsightDiv.find(".modelname").text(TempoUtils.locale("mine.modelname") + "：" + modelVersion.substring(0, idx));
        pmmlInsightDiv.find(".copyright").text(TempoUtils.locale("mine.copyright") + "：" + copyRight);
        pmmlInsightDiv.find(".pmmlxieyi").text(TempoUtils.locale("mine.pmmlxieyi") + "：" + pmmlVersion);
        pmmlInsightDiv.find(".modelversion").text(TempoUtils.locale("mine.modelversion") + "：" + modelVersion.substring(idx + 1));
        pmmlInsightDiv.find(".algname").text(TempoUtils.locale("mine.algname") + "：" + (nodeIdToNameMap[modelName] || modelName));
        pmmlInsightDiv.find(".timestamp").text(TempoUtils.locale("mine.timestamp") + "：" + timestamp)
        pmmlInsightDiv.find(".filednames").text(dataDictionaryStr);
        pmmlInsightDiv.find(".labelcolumns").text(labelStr);
        pmmlInsightDiv.find(".predictioncolumns").text(predictFiledStr);
    }

    /**
     * 信号处理模块洞察公共表格表头
     * @returns {[string, string, string, string, string]}
     * @constructor
     */
    TempoMineInsightUtils.SIGNAL_RESULT_TABLE_HEAD = function () {
        var resultTableHead = ["名称", "起始时间", "采样率", "信号数据", "信号长度"];
        return resultTableHead;
    };

    /**
     * 展示空模型洞察
     */
    TempoMineInsightUtils.showNullModelInsight = function (body) {
        $('<div class="mine-model-null-div" style="margin-bottom:10px;"><lable ">数据集为空，共0行，暂无模型</lable></div>').appendTo(body);
    }

    /**
     * 展示空图表洞察
     */
    TempoMineInsightUtils.showNullGraphInsight = function (body) {
        $('<div class="mine-graph-null-div" style="margin-bottom:10px;margin-top: 10px;"><lable >数据集为空，共0行，暂无图表</lable></div>').appendTo(body);
    }

    /**
     * 展示数据集空洞察
     * @param body
     */
    TempoMineInsightUtils.showNullDatasetInsight = function (body) {
        $('<div class="mine-dataset-null-div" style="display: block;margin-bottom:10px;"><lable >数据集为空，共0行</lable></div>').appendTo(body);
    }

    /**
     * 展示节点洞察空数据集
     * @param body
     */
    TempoMineInsightUtils.showNullNodeInsight = function (body) {
        $('<div class="mine-nodeDataset-null-div" style="display: block;margin-bottom:10px;"><lable >数据集为空，共0行</lable></div>').appendTo(body);
    }
    /**
     * 展示关联分类下模型空数据集洞察
     * @param body
     */
    TempoMineInsightUtils.showNullAPFPInsight = function (body) {
        $('<div class="mine-ruleDataset-null-div" style="display: block;margin:5px 0 10px 0px;"><lable >暂无模型</lable></div>').appendTo(body);
    }

    /**
     * 展示关联分类下序列模型空数据集洞察
     * @param body
     */
    TempoMineInsightUtils.showNullSequeInsight = function (body) {
        $('<div class="mine-sequeDataset-null-div" style="display: block;margin:5px 0 10px 0px;"><lable >置信度为空，共0行，暂无模型</lable></div>').appendTo(body);
    }


})(jQuery);